package safari.model.faq;

import java.sql.SQLException;
import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;

public class FAQDaoImpl implements FAQDao {
	private SqlSessionTemplate sqlSessionTemplate;
	
	public FAQDaoImpl(SqlSessionTemplate sqlSessionTemplate) {
		super();
		this.sqlSessionTemplate = sqlSessionTemplate;
	}
	//글 등록
	@Override
	public void insertBoard(FAQBoardVO fvo) throws SQLException {
	sqlSessionTemplate.insert("faq.insertBoard", fvo);
	}
	//글 삭제
	@Override
	public void deleteBoard(int no) throws SQLException {
	sqlSessionTemplate.delete("faq.deleteBoard",no);
	}
	//글 수정
	@Override
	public void updateBoard(FAQBoardVO fvo) throws SQLException {
	sqlSessionTemplate.update("faq.updateBoard",fvo);
	}
	//조회수 1 증가
	@Override
	public int updateHits(int no) throws SQLException {
		return sqlSessionTemplate.update("faq.updateHits",no);
	}
	//글번호로 글찾기
	@Override
	public FAQBoardVO selectBoardByNo(int no) throws SQLException {
		return sqlSessionTemplate.selectOne("faq.selectBoardByNo", no);
	}
	//모든 글 찾기
	@Override
	public List<FAQBoardVO> selectAllBoard() throws SQLException {
		return sqlSessionTemplate.selectList("faq.selectAllBoard");
	}
	//모든 글 갯수
	@Override
	public int getTotalContents() throws SQLException {
		return sqlSessionTemplate.selectOne("faq.getTotalContents");
	}
	//제목으로 글찾기
	@Override
	public List<FAQBoardVO> selectBoardByTitle(String title)
			throws SQLException {
		return sqlSessionTemplate.selectList("faq.selectBoardByTitle", title);
	}
	//내용으로 글찾기
	@Override
	public List<FAQBoardVO> selectBoardByContent(String content)
			throws SQLException {
		return sqlSessionTemplate.selectList("faq.selectBoardByContent", content);
	}
	//제목+내용으로 글찾기
	@Override
	public List<FAQBoardVO> selectBoardByTitleOrContent(String keyword)
			throws SQLException {
		return sqlSessionTemplate.selectList("faq.selectBoardByTitleOrContent", keyword);
	}
	@Override
	public int getTotalContentsByTitleOrContent(String keyword)
			throws SQLException {
		return sqlSessionTemplate.selectOne("faq.getTotalContentsByTitleOrContent", keyword);
	}
	@Override
	public int getTotalContentsByTitle(String title) throws SQLException {
		return sqlSessionTemplate.selectOne("faq.getTotalContentsByTitle", title);
	}
	@Override
	public int getTotalContentsByContent(String content) throws SQLException {
		return sqlSessionTemplate.selectOne("faq.getTotalContentsByContent",content);
	}
	@Override
	public int getHitsByNo(int no) throws SQLException {
		return sqlSessionTemplate.selectOne("faq.selectHitsByNo", no);
	}
	@Override
	public List<FAQBoardVO> selectBoardByCategory(String category)
			throws SQLException {
		return sqlSessionTemplate.selectList("faq.selectBoardByCategory", category);
	}
	@Override
	public int getTotalContentsByCategory(String category) throws SQLException {
		return sqlSessionTemplate.selectOne("faq.getTotalContentsByCategory", category);
	}

}
